package cn.edu.zafu.bigdata.x.zhaobolei.Fifth;

public class ArrayExample {
    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("数组下标过大");
        }
        return arr[index];
    }

    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5};
        try {
            int element1 = getElement(array, 3);
            System.out.println("Element：" + element1);

            int element2 = getElement(array, 5);
            System.out.println("Element：" + element2);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Error：" + e.getMessage());
        }
    }
}
